function checkWaitStatus(basePath, sessionId,url) {
	var status;
	coolio.xhrGet({
		url : basePath + 'question/check_session',
		handleAs : "json",
		content : {
			sessionId : sessionId
		},
		handle : function(data) {
			if (data.status == 2||data.status == 3) {
				if (confirm("Your friend has entered the chatting room, Do you want to proceed?")) {
					window.onbeforeunload = null;
					window.location.href = url;
				}
			}
		},
		error : function(response, ioArgs) {
			alert("xhr get failed:");
			return response;
		}
	});
	return status;
}

function checkChatStatus(basePath, sessionId,questionId, requestUrl, terminateUrl, chatUrl) {
	var status;
	coolio.xhrGet({
		url : basePath + 'question/check_session',
		handleAs : "json",
		content : {
			sessionId : sessionId,
			questionId : questionId
		},
		handle : function(data) {
			var url=requestUrl;
			if (data.status == 4) {
				if (confirm("You friend has left the chatting room temporaily. Do you want to leave?")) {
					window.onbeforeunload = null;
					window.location.href = terminateUrl;
				} else {
					activateSession(basePath,sessionId);
				}
			}else if(url.indexOf("pre_chat")!=-1&data.questionStatus==5){
				if (confirm("Do you want to start chatting about the question?")) {
					window.onbeforeunload = null;
					window.location.href =chatUrl;
				}
			}
		},
		error : function(response, ioArgs) {
			alert("xhr get failed:");
			return response;
		}
	});
	return status;
}

function deactivateSession(basePath,sessionId){
	coolio.xhrGet({
		url: basePath+'question/deactivate_session',
   		handleAs: "json",
   		content: {
   			sessionId: sessionId
	    },
		handle:function(data){
		},
		error: function(response, ioArgs){
	    	return response;
		}
	});
}

function activateSession(basePath,sessionId){
	var href=window.location.href.substring(basePath.length+'question'.length-2,window.location.href.indexOf('?'));
	coolio.xhrGet({
		url: basePath+'question/activate_session',
   		handleAs: "json",
   		content: {
   			type: href,
   			sessionId: sessionId
	    },
		handle:function(data){
		},
		error: function(response, ioArgs){
	    	return response;
		}
	});
}